/*
 *
 *方法的整理与重构
 *
 *
 */

//定义app参数名称，并加载其它模块
var authApp=angular.module('authapp', ["ngCookies",'ngFileUpload','ui.bootstrap']);

//此为定位页面所用
authApp.value('page','courseAnalyseList');

/*controller部分*/

//主要操作controller
authApp.controller("opinionEditController",function($scope,$http,$getQueryString,$timeout,$sce){
    $scope.schoolId = $getQueryString("schoolId");
    $scope.schoolName = decodeURIComponent($getQueryString("schoolName"));
    $scope.sign = $getQueryString("sign");
    $scope.state = $getQueryString("state");
    $scope.f = parseInt($getQueryString("f"));
    $scope.pid = $getQueryString('pid')
    var pid = 0
    var queryMainApi=apis.queryOneCA;
    var requestJson={'schoolId':$scope.schoolId,'sign':decodeURIComponent($scope.sign)};
    $scope.queryMain=function(){
        $http({
            method:'post',
            url:queryMainApi,
            data:requestJson,
        }).success(function(response){
            if(response.code=="000000"){
                $scope.kind = response.data.kind;
                $scope.reportingTime = response.data.reportingTime;
                $scope.talkCourse = response.data.talkCourse;
                $scope.courseName = response.data.courseName;
                $scope.technicalTitle = response.data.technicalTitle;
                $scope.post = response.data.post;
                $scope.talkCourseContent = response.data.talkCourseContent;
                $scope.generalComment = response.data.generalComment;
                $scope.suggest = response.data.suggest;
                pid = response.data.pid
            }else{
                alert(response.errorMsg);
            }
        }).error(function(){
            alert("网络出现故障，请确认网络是否连接");
        })
    }
    $scope.queryMain();
    $scope.down=function() {
        return window.open('/views/investiga/table11.html?schoolId='+ $scope.schoolId+'&schoolName='+ encodeURIComponent($getQueryString("schoolName")) + '&sign=' + $scope.sign + '&state='+ $scope.state + '&f='+$scope.f+'&pid='+ $scope.pid)
    }
    $scope.upadteData = function() {
        if(window.confirm("是否确认保存？")){
            var requestJson={
                'pid': pid,
                'kind':$scope.kind,
                'reportingTime':$scope.reportingTime,
                'talkCourse':$scope.talkCourse,
                'courseName':$scope.courseName,
                'technicalTitle':$scope.technicalTitle,
                'post':$scope.post,
                'talkCourseContent':$scope.talkCourseContent,
                'generalComment':$scope.generalComment,
                'suggest':$scope.suggest};
            $http({
                method:'post',
                url:apis.updateCourseAnalyse,
                data:requestJson,
            }).success(function(response){
                if(response.code=="000000"){
                    alert("保存成功！");
                    $scope.state = '1';
                    $scope.queryMain();
                }else{
                    alert(response.errorMsg);
                }
            }).error(function(){
                alert("网络出现故障，请确认网络是否连接");
            })
        }  
    }
    //保存
    $scope.saveData=function(){
        if(window.confirm("是否确认保存？")){
            var requestJson={
                'schoolId':$scope.schoolId,
                'kind':$scope.kind,
                'reportingTime':$scope.reportingTime,
                'talkCourse':$scope.talkCourse,
                'courseName':$scope.courseName,
                'technicalTitle':$scope.technicalTitle,
                'post':$scope.post,
                'sign':decodeURIComponent($scope.sign),
                'talkCourseContent':$scope.talkCourseContent,
                'generalComment':$scope.generalComment,
                'suggest':$scope.suggest};
            $http({
                method:'post',
                url:apis.saveCourseAnalyse,
                data:requestJson,
            }).success(function(response){
                if(response.code=="000000"){
                    alert("保存成功！");
                    $scope.state = '1';
                    $scope.queryMain();
                }else{
                    alert(response.errorMsg);
                }
            }).error(function(){
                alert("网络出现故障，请确认网络是否连接");
            })
        }
    }


    //返回到前页面
    $scope.goback=function(){
        //if(window.confirm("是否确认返回？")){
            javascript:history.back(-1);
        //}
    }
    function unUnicode(str)
    {
        return unescape(str.replace(/\\/g, "%"));
    }

})

function toUnicode(str)
    {
        return escape(str).replace(/%/g,"\\").toLowerCase();
    }